package com.jufanshare.myblog.service.typecolumn;

import com.jufanshare.myblog.dao.TypeColumnDao;
import com.jufanshare.myblog.entity.TypeColumn;
import com.jufanshare.myblog.service.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作用：
 * 作者：Tiddler
 * 时间：2019/1/21 18：56
 * 类名： TypeColumnServiceImpl
 **/
@Service
@CacheConfig(cacheNames = "typecolumn")
public class TypeColumnServiceImpl extends BaseServiceImpl<TypeColumn> implements TypeColumnService {
    @Autowired
    private TypeColumnDao typeColumnDao;
    @Cacheable(cacheNames = "findTypeByColumn")
    @Override
    public List<TypeColumn> findTypeByColumn(int columnId) {
        TypeColumn typeColumn=new TypeColumn();
        typeColumn.setUpid(columnId);
        return template(typeColumn);
    }
    @Cacheable(cacheNames = "templateOne")
    @Override
    public TypeColumn templateOne(int columnId) {
        TypeColumn typeColumn=new TypeColumn();
        typeColumn.setId(columnId);
        return templateOne(typeColumn);
    }
    //刷新templateOne缓存只是顺带的
    @CacheEvict(cacheNames = {"findTypeByColumn","templateOne"},allEntries = true)
    @Override
    public void articleNumberAdd(TypeColumn typeColumn) {
        typeColumnDao.articleNumberAdd(typeColumn);
    }
}
